﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1ExtensionMethods
{
    public static class IEnumarableT
    {
        public static T Sum<T>(this IEnumerable<T> members)
        {
            T sum = default(T);
            foreach (T member in members)
            {
                sum = sum + (dynamic)member;
            }
            return sum;
        }

        public static T Product<T>(this IEnumerable<T> members)
        {
            int product = 1;
            foreach (T item in members)
            {
                product = product * (dynamic)item;
            }
            return (dynamic)product;
        }

        public static T MinElement<T>(this IEnumerable<T> members)
        {
            T min = members.First();

            foreach (var member in members)
            {
                if ((dynamic)member < min)
                {
                    min = member;
                }
            }

            return min;
        }

        public static T MaxElement<T>(this IEnumerable<T> members)
        {
            T max = members.First();

            foreach (var member in members)
            {
                if ((dynamic)member > max)
                {
                    max = member;
                }
            }

            return max;
        }
        public static T Average<T>(this IEnumerable<T> members)
        {
            T average = default(T);
            average = members.Sum()/(dynamic)members.Count();

            return average;
        }
    }
}
